﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LayerEntity.Almacen;

namespace System2012.Almacen.Consultas
{
    public partial class BuscarAlmacen : DevExpress.XtraEditors.XtraForm 
    {
        public BuscarAlmacen()
        {
            InitializeComponent();
        }

        public EAlmacen Almacen { get; private set; }
        public bool Estado { get; private set; }

        private void BuscarAlmacen_Load(object sender, EventArgs e)
        {
            Estado = false;
            BGWLoadAlmacen.RunWorkerAsync();
        }

        private void BgwLoadAlmacenDoWork(object sender, DoWorkEventArgs e)
        {
            BGWLoadAlmacen.ReportProgress(10, "Loading Almacenes");
            e.Result = SystemUtils.RecordmanagerAlmacen.GetAlmacen();
            BGWLoadAlmacen.ReportProgress(100, "Completado");
        }

        private void BgwLoadAlmacenRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            gridControl1.DataSource = e.Result;
        }

        private void BgwLoadAlmacenProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBarControl1.EditValue = e.ProgressPercentage;
            lblProgreso.Text = e.UserState.ToString();
        }

        private void GridView1DoubleClick(object sender, EventArgs e)
        {
            if (gridView1.RowCount > 0)
            {
                EAlmacen alm = (EAlmacen) gridView1.GetFocusedRow();
                if (alm != null)
                {
                    Almacen = alm;
                    Estado = true;
                    this.Close();
                }
            }
        }
    }
}